/**
 * v-dept
 * 按钮权限指令
 */
import { authStore } from "@/stores/modules/auth";
import type { Directive, DirectiveBinding } from "vue";
import { routerStore } from "@/stores/modules/router";

const auth: Directive = {
  mounted(el: HTMLElement, binding: DirectiveBinding) {
    const { value } = binding;
    const authState = authStore();
    const routerState = routerStore();
    if (authState.user?.is_admin) {
      return;
    }
    const authKey = value + ":" + routerState.routeId;
    if (!authState.operations[authKey]) {
      el.remove();
    }
  }
};

export default auth;
